package cn.kgc.springcloud.controller;

import cn.kgc.springcloud.entity.Tag;
import cn.kgc.springcloud.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @author: 课工场
 * @since 2023/9/11
 */
@RestController
@RequestMapping("tag")
public class TagController {

    @Autowired
    private TagService tagService;

    // 获取标签列表
    @GetMapping("list")
    public List<Tag> tagList() {
        List<Tag> list = tagService.list();
        return list;
    }

    // 根据id  删除标签
    @DeleteMapping("/delete/{id}")
    public Boolean deleteTag(@PathVariable("id") Integer id) {

        return tagService.removeById(id);
    }

    // 添加标签
    @PostMapping("add")
    public Tag addTag(@RequestBody Tag tag) {
        tag.setCreatedate(new Date());
        tagService.save(tag);
        return tag;
    }

    //根据标签id获取标签详细信息
    @GetMapping("getById/{id}")
    public Tag getTagById(@PathVariable("id") Integer id) {
        return  tagService.getById(id);
    }


}
